#!usr/bin/node

//实例化一个buffer对象
let buf = new Buffer(256);

//初始化第一个buffer为定值
buf[0] = 23;

//打印Buffer的长度
console.log("buffer length:", buf.length);
console.log("\nbuffer content:", buf);

for (let i = 0; i < 256; i++) {
  buf[i] = i;
  console.log("\nbuffer content:", buf);
};

//切片buffer
let end = buf.slice(250, 256);
console.log("end buffer:", end);

//填充字节为0
end.fill(0);
console.log("end buffer -6:", end);

let array = ['a', 0xba, 0xdf, 0x00, 255, 10];
let buf1 = new Buffer(array);
console.log("\nbuf1:", buf1.length, buf1);

let buf2 = new Buffer("hello world", 'utf8');
console.log("buf2:", buf2.toString());

let buf3 = new Buffer(buf2.length);
buf2.copy(buf3, 0, 0, buf2.length);
console.log("\nbuf3:", buf3.length, buf3.toString());
